import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
} from '@nestjs/common';
import { RuleInfoService } from './rule-info.service';
import { CreateRuleInfoDto } from './dto/create-rule-info.dto';
import { UpdateRuleInfoDto } from './dto/update-rule-info.dto';
import { PageQuery } from '../../../util/entity/page.entity';
import { Role } from '../role/entities/role.entity';
import { HasPerms } from '../../../common/decorator/my.decorator';
import { Perm } from '../../../util/enum/perm.enum';

@Controller()
export class RuleInfoController {
  constructor(private readonly ruleInfoService: RuleInfoService) {}

  @HasPerms(Perm.SysRuleInfoAdd)
  @Post()
  create(@Body() createRuleInfoDto: CreateRuleInfoDto) {
    return this.ruleInfoService.create(createRuleInfoDto);
  }

  @Post('list')
  findAll(@Body() pageQuery: PageQuery<Role>) {
    return this.ruleInfoService.findAll(pageQuery);
  }

  @HasPerms(Perm.SysRuleInfoEdit)
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.ruleInfoService.findOne(id);
  }

  @HasPerms(Perm.SysRuleInfoEdit)
  @Patch(':id')
  update(
    @Param('id') id: number,
    @Body() updateRuleInfoDto: UpdateRuleInfoDto,
  ) {
    return this.ruleInfoService.update(id, updateRuleInfoDto);
  }

  @HasPerms(Perm.SysRuleInfoDelete)
  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.ruleInfoService.remove(id);
  }
}
